<template>
  <div class="content">
    <div class="msg">注意：数据会有10分钟左右延迟</div>
    <el-table
      :data="tableData"
      style="width: 100%"
      class="tableData"
      @sort-change="sortChange"
    >
      <el-table-column
        prop="mini_app_name"
        label="小程序"
        width="180"
      >
        <template slot-scope="{ row }">
          <p>{{ row.mini_app_name }}
            <svg-icon
              v-if="row.app_type==1"
              icon-class="miniapp"
              class="imageIcon"
            />
            <svg-icon
              v-else
              icon-class="douyin"
              class="imageIcon"
            />
          </p>
          <p class="infoText">{{ row.mini_app_id }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="id"
        label="用户ID"
        width="160"
      >
        <template slot-scope="{ row }">
          <p
            style="cursor: pointer;color:#06C261"
            @click="showDetails(row)"
          >{{ row.id }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="reg_time"
        label="注册时间"
        width="110"
      >
        <template slot-scope="{ row }">
          <p>{{ row.reg_time.split(' ')[0] }}</p>
          <p>{{ row.reg_time.split(' ')[1] }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="distributor_name"
        label="分销方"
      >
      </el-table-column>
      <el-table-column
        label="染色渠道"
        prop="channel_name"
      >
        <template slot-scope="{ row }">
          <p>{{ row.channel_name }}</p>
          <p class="infoText">{{ row.channel_id }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="seq_time"
        label="染色时间"
        width="110"
      >
        <template slot-scope="{ row }">
          <p>{{ row.seq_time.split(' ')[0] }}</p>
          <p>{{ row.seq_time.split(' ')[1] }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="vip_end_time"
        label="会员截止时间"
        width="110"
      >
        <template slot-scope="{ row }">
          <p>{{ row.vip_end_time.split(' ')[0] }}</p>
          <p>{{ row.vip_end_time.split(' ')[1] }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="last_playlet"
        label="最近观看剧集"
        width="110"
      >
      </el-table-column>
      <el-table-column
        prop="surplus_coin"
        label="剩余喵币"
        align="right"
      >
        <template slot-scope="{ row }">
          <p> {{ formatNumber(row.surplus_coin) }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="surplus_free_coin"
        label="剩余赠币"
        align="right"
      >
        <template slot-scope="{ row }">
          <p> {{ formatNumber(row.surplus_free_coin) }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="total_recharge_num"
        label="累计充值次数"
        align="right"
        width="120"
      >
      </el-table-column>

      <el-table-column
        prop="total_amount"
        label="累计充值金额"
        align="right"
        sortable="custom"
        width="130"
      >
        <template slot-scope="{ row }">
          <p> {{ formatNumber(row.total_amount) }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="last_login_time"
        label="最后活跃时间"
        width="110"
      >
        <template slot-scope="{ row }">
          <p>{{ row.last_login_time.split(' ')[0] }}</p>
          <p>{{ row.last_login_time.split(' ')[1] }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="internal"
        label="内部账号"
        width="80"
      >
        <template slot-scope="{ row }">
          <p>{{ row.internal==1?'是':'否' }}</p>
        </template>
      </el-table-column>
      <el-table-column
        prop="system_type"
        label="用户系统"
        width="80"
      >
        <template slot-scope="{ row }">
          <p>{{ row.system_type==1?'安卓':row.system_type==2 ? 'IOS' : "" }}</p>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        width="120"
      >
        <template slot-scope="{ row }">
          <div>
            <el-button
              v-if="row.status==1"
              style="font-size:14px;"
              type="text"
              @click="prohibit(row)"
            >一键封禁</el-button>
            <el-button
              v-else
              type="text"
              style="color:#F56C6C;font-size:14px;cursor: pointer;"
              @click="prohibit(row)"
            >解除封禁</el-button>
          </div>
          <div>
            <el-button
              v-permission:examine-internal
              style="font-size:14px;"
              :class="row.internal == 1?'redColor':'' "
              type="text"
              @click="startAccount(row)"
            >{{ row.internal == 1 ? '取消' : '开启' }}内部账号</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <BiDrawer
      v-model="drawer.visible"
      :row-info="drawer.row"
      drawer-title="用户详情"
      :component="userDetails"
      drawer-size="65%"
      @ok="onSubmit"
    ></BiDrawer>
  </div>
</template>
<script>
import { memberStatus, internalMember } from '@/api/userPage'
import BiDrawer from '@/components/BiDrawer'
import userDetails from './detailsLayer.vue'
import { formatNumber } from '@/utils/index'
export default {
  components: {
    BiDrawer
  },
  props: ['tableData'],
  data() {
    return {
      formatNumber: formatNumber,
      drawer: {
        visible: false,
        row: {},
        title: '用户详情'
      },
      userDetails: userDetails
    }
  },
  mounted() {},
  methods: {
    handleSelectionChange() {},
    showDetails(row) {
      this.drawer.row = row
      this.drawer.row.member_id = row.id
      this.drawer.visible = true
    },
    sortChange(column) {
      console.log(column.order)
      this.$emit('orderChange', column.order)
    },
    onSubmit() {},
    startAccount(row) {
      this.$confirm(`确定${row.internal == 1 ? '取消' : '开启'}用户ID${row.id}为内部账号?，${row.internal == 1 ? '取消' : '开启'}后,该账号${row.internal == 1 ? '为普通账号，需付费解锁短剧' : '在小程序中看所有剧无须付费'}`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.accountStatus(row)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    prohibit(row) {
      this.$confirm(`确定将该用户${row.status == 1 ? '封禁' : '解封'}吗?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.memberStatus(row)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    memberStatus(row) {
      const data = {
        id: row.id,
        status: row.status == '1' ? '2' : '1'
      }
      memberStatus(data).then((res) => {
        if (res.status_code === 1) {
          this.$emit('resizeList')
          this.$message.success(res.msg)
        }
      })
    },
    accountStatus(row) {
      const data = {
        id: row.id,
        status: row.internal == '1' ? '2' : '1'
      }
      internalMember(data).then((res) => {
        if (res.status_code === 1) {
          this.$emit('resizeList')
          this.$message.success(res.msg)
        }
      })
    }
  }
}
</script>

  <style lang="scss" scoped>
.content {
  width: 100%;
  overflow-x: auto;
}
.redColor {
  color: #f56c6c;
  font-weight: 400;
}
.image {
  width: 50px;
  border-radius: 5px;
}
.msg {
  font-size: 14px;
  color: rgb(108, 108, 108);
  padding: 0 0 10px 0px;
}
</style>